package com.zyw.codegen.java;

import com.zyw.codegen.GeneratorContextHolder;
import org.mybatis.generator.codegen.AbstractJavaGenerator;

/**
 * @author zhangyw
 * @date 2017/3/15 11:14
 */
public abstract class MVCGenerator extends AbstractJavaGenerator {

    protected static final String PACKAGE_CONTROLLER = "controller";
    protected static final String PACKAGE_SERVICE = "service";

    private String rootClass;

    @Override
    public String getRootClass() {
        return rootClass;
    }

    public void setRootClass(String rootClass) {
        this.rootClass = rootClass;
    }

    protected String getControllerClassName() {
        StringBuffer sb = new StringBuffer();
        sb.append(GeneratorContextHolder.genConfig().getPackageName());
        sb.append('.');
        sb.append(PACKAGE_CONTROLLER);
        sb.append('.');
        sb.append(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
        sb.append("Controller");
        return sb.toString();
    }

    protected String getServiceClassName() {
        StringBuffer sb = new StringBuffer();
        sb.append(GeneratorContextHolder.genConfig().getPackageName());
        sb.append('.');
        sb.append(PACKAGE_SERVICE);
        sb.append('.');
        sb.append(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
        sb.append("Service");
        return sb.toString();
    }

    protected String getBaseRequestPath() {
        return (GeneratorContextHolder.genConfig().getModuleName() + "/" + introspectedTable.getFullyQualifiedTable().getDomainObjectName()).toLowerCase();
    }

}
